/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Client;

import Server.User;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 *
 * @author windsea
 */
public class ClientView extends JFrame {
    private JTextField txtID;
    private JPasswordField txtPW;
    private JButton btnRegister;
    private JButton btnLogin;
    String hostname, ipAdd;
    
    public ClientView(){
        super("Client Remote Control");
        getIP();
        txtID = new JTextField(15);
        txtPW = new JPasswordField(15);
        txtPW.setEchoChar('*');
        btnRegister = new JButton("Register");
        btnLogin = new JButton("Login");
        JPanel content = new JPanel();
        content.setLayout(new GridLayout(0,1));
        content.add(new JLabel("ID: "));
        content.add(txtID);
        content.add(new JLabel("Password: "));
        content.add(txtPW);
        content.add(btnRegister);
        content.add(btnLogin);
        
        content.add(new JLabel("IP address: "+ipAdd));
        content.add(new JLabel("Hostname: "+hostname));
        this.setContentPane(content);
        this.pack();
    }
    
    public void actionPerformed(ActionEvent e){
        
    }
    
    void showMessage(String msg){
        JOptionPane.showMessageDialog(this, msg);
    }
    public void addLoginListener(ActionListener log) {
        btnLogin.addActionListener(log);
    }
    public void addRegisterListener(ActionListener log) {
        btnRegister.addActionListener(log);
    }
    public User getUser() {
        User model = new User(txtID.getText(),
                txtPW.getText());
        return model;
    }
    
    void getIP(){
        try {
    InetAddress addr = InetAddress.getLocalHost();

    // Get IP Address
    //byte[] ipAddr = addr.getAddress();
    ipAdd = addr.getHostAddress();
    // Get hostname
    hostname = addr.getHostName();
     System.out.println(ipAdd+"      "+hostname);
    } catch (UnknownHostException e) {
    }
    }
    
}
